<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="database.DAO, golf.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
	request.setCharacterEncoding("utf-8");
	DAO dao = DAO.getInstance();
	int channelNo = (Integer)session.getAttribute("channelNo");
	int charNo = (Integer)session.getAttribute("charNo"); //방 생성자
	
	int levelLimit = 0; //lvl
	int playerCntLimit = 0; //howmany
	int Enzi = 0; //enzi
	int courseNo = Integer.parseInt(request.getParameter("course"));
	int holeCnt = Integer.parseInt(request.getParameter("numOfHoles"));
	String gameType = request.getParameter("type");
	String password = null;
	String roomName = request.getParameter("roomName");
	
	if(request.getParameter("lvl").compareTo("") != 0){
		levelLimit = Integer.parseInt(request.getParameter("lvl"));
	}
	if(request.getParameter("howmany").compareTo("") != 0){
		playerCntLimit = Integer.parseInt(request.getParameter("howmany"));
	}
	if(request.getParameter("enzi").compareTo("") != 0){
		Enzi = Integer.parseInt(request.getParameter("enzi"));
	}
	
	Room room = new Room();
	room.setRoomType(Room.ROOMTYPE_GAME);//
	room.setChnNo(channelNo);//
	room.setLimit_level(levelLimit);//
	room.setLimit_person_no(playerCntLimit);//
	room.setPassword(password);//
	room.setName(roomName);//
	Room.Game game = new Room.Game();//
	game.setCourse_no(courseNo);
	game.setHole_cnt(holeCnt);
	game.setEnzi(Enzi);
	game.setGame_type(gameType);//
	room.setGame(game);//
	int roomNo = 0;
	if( (roomNo = dao.createGame(charNo, room)) > 0 ){
		session.setAttribute("roomNo", roomNo );
		System.out.println("roomNo(" + roomNo + ")세션 추가 완료!");
		response.sendRedirect("../jsp/gameRoom.jsp");
		
	}
	
	
 %>
</body>
</html>